#include "llcomp_llc.h" 

    

        typedef  struct Body_struct{  double mass;  double pos [2];  double vel [2];}  Body;
     
     void loopParallelFor0_support(  int *_num_bodies,  double *_dist,  double *r,  int *_j,  Body *bodies,  double *_dt,  int *_i,  double *_force_len,  double *tot_force_i,  double *dv,  double *force_ij) ;
     void loopParallelFor0_support(  int *_num_bodies,  double *_dist,  double *r,  int *_j,  Body *bodies,  double *_dt,  int *_i,  double *_force_len,  double *tot_force_i,  double *dv,  double *force_ij)  {
                 int num_bodies = *_num_bodies;
                 double dist = *_dist;
                 int j = *_j;
                 double dt = *_dt;
                 int i = *_i;
                 double force_len = *_force_len;
        /* Begin template: forall_init_unit.tmpl */

/* $0 => Variable del bucle
 * loop_initial => Valor inicial de la variable del bucle B
 * loop_finalice => Valor final de la variable del bucle C
 */

{
    int llc_meanT, llc_rnT;
    register int llc_i;

    llc_nT = ((num_bodies - 1) - (0) + 1);
    /* Medium number of tasks */
    llc_meanT = llc_nT / LLC_NUMPROCESSORS;
    /* Number of unassigned tasks */
    llc_rnT = llc_nT % LLC_NUMPROCESSORS;

    LLC_CHECK_MALLOC (llc_F, (LLC_NUMPROCESSORS + 1), int);

    llc_F[0] = 0;
    for (llc_i = 1; llc_i < (LLC_NUMPROCESSORS + 1); llc_i++) {
        llc_F[llc_i] = llc_F[llc_i-1] + llc_meanT + (((llc_i - 1) < llc_rnT) ? 1 : 0);
    }
}

/* End template: forall_init_unit.tmpl */
/* Begin template: forall_exec_unit.tmpl */

/* loop_var => Variable del bucle
 * loop_initial => Valor inicial de la variable del bucle
 * loop_stmt => Bloque del bucle
 */

{
    int llc_nP;
    int llc_grp_save;
    register int llc_i;

    llc_nP = LLC_NUMPROCESSORS;
    llc_grp_save = LLC_NAME;
    LLC_NUMPROCESSORS = 1;
    LLC_NAME = 0;
    
    i = (0) + llc_F[llc_grp_save];
    for (llc_i = 0; llc_i < LLC_PROCSGRP(llc_grp_save); llc_i++, i++) {
        
{

tot_force_i[0]= 0.0;
tot_force_i[1]= 0.0;
  for (j= 0; j < num_bodies; (j++ ))  
{

    if     (j == i    )     continue     ;;
r[0]= bodies[j].pos [0] - bodies[i].pos [0];
r[1]= bodies[j].pos [1] - bodies[i].pos [1];
dist= (r[0] * r[0]) + (r[1] * r[1]);
force_len= ((6.673e-11 * bodies[i].mass ) * bodies[j].mass ) / (dist * sqrt(dist) );
force_ij[0]= force_len * r[0];
force_ij[1]= force_len * r[1];
tot_force_i[0]+= force_ij[0];
tot_force_i[1]+= force_ij[1];
  }

 ;
dv[0]= (dt * tot_force_i[0]) / bodies[i].mass ;
dv[1]= (dt * tot_force_i[1]) / bodies[i].mass ;
bodies[i].pos [0]+= dt * (bodies[i].vel [0] + (dv[0] / 2));
bodies[i].pos [1]+= dt * (bodies[i].vel [1] + (dv[1] / 2));
bodies[i].vel [0]+= dt * dv[0];
bodies[i].vel [1]+= dt * dv[1];
}

;
    }

    LLC_NAME = llc_grp_save;
    LLC_NUMPROCESSORS = llc_nP;
}

/* End template: forall_exec_unit.tmpl */
/* Begin template: forall_exit.tmpl */

    free(llc_F);
    llc_F = NULL;

/* End template: forall_exit.tmpl */

                *_num_bodies = num_bodies;
                *_dist = dist;
                *_j = j;
                *_dt = dt;
                *_i = i;
                *_force_len = force_len;

    }

    